using System.Collections.Generic;
using System.Linq;
using DL.Tools;
using UnityEngine;

namespace DL.AudioSystem
{
    [CreateAssetMenu(fileName = "AudioMap", menuName = "Create/Audio/AudioMap")]
    public class AudioMap : ScriptableObject
    { 
        [SerializeField]private List<SoundData> m_SFXSoundDatas;
       
        [SerializeField]private List<SoundData> m_BGMSoundDatas;
        
        private Dictionary<SoundType, List<SoundData>> m_SoundDataMap;
        public Dictionary<SoundType, List<SoundData>> SoundDataMap => m_SoundDataMap;

        public void Init()
        {
            var datas = m_BGMSoundDatas.Concat(m_SFXSoundDatas);
            Debugger.EO_Log("AudioMap初始化");

            m_SoundDataMap ??= new();
            foreach (var sound in datas)
            {
                if (!m_SoundDataMap.TryGetValue(sound.soundType, out var list))
                {
                    list = new();
                    m_SoundDataMap.Add(sound.soundType, list);
                }
                sound.Init();
                list.Add(sound);
            }

            // Print();
        }

        private void Print()
        {
            foreach (var data in m_SoundDataMap)
            {
                Debugger.EO_Log($"打印{data.Key.ToString()}类型数据");
                foreach (var item in data.Value)
                {
                    Debugger.EO_Log(item.name);
                }
                Debugger.EO_Log($"打印{data.Key.ToString()}类型数据打印完毕");
            }
        }
    }
    
}
